import React from 'react';
// import PureRenderMixin from 'react-addons-pure-render-mixin';

import {getData} from '../../../fetch/get'

export default class Ad extends React.Component {
  constructor(props) {
    super(props);
    // this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate
    this.state = {
      data: []
    }
  }

  render() {
    return (
      <div>
        <ul className="flex_row flex_space_between flex_wrap">
          {this.state.data.map((item,index)=>{
            return <li className="col-3" key={index}>
              <p>{item.id}</p>
              <p>{item.title}</p>
              <p>{item.price}</p>
            </li>
          })}
        </ul>
      </div>
    )
  }

  componentDidMount() {
    let result = getData();
    console.log(result);
    result.then(res => res.json())
      .then(res => {
        console.log(res);
        if (res.length) {
          this.setState({
            data: res
          })
        }
      });
    console.log("组件加载完成");

  }
}